package fanxing.demo03;

/**
 * @author Mr.ma
 * @since 2022/10/25 14:27
 * 用于测试泛型的上下限
 * 泛型上限<? extends xxxClass>：extends关键字，
 *     表示该类及其子类，泛型上限要求传入参数类型需小于等于上限
 * 泛型下限<? super xxxClass>；super关键字，
 *     表示该类及其父类，泛型下限要求传入参数类型需大于等于下限
 * 泛型的上限和下限无法作为方法重载使用
 **/
public class Test03 {
    public static void main(String[] args) {
        doSome(new Info<>(1));
        doSome(new Info<>(3.1415926));
        doSome(new Info<>(11111111111L));

        doOther(new Info<>(new Exception("异常类")));
        doOther(new Info<>(new RuntimeException("运行时异常类")));
    }
    public static void doSome(Info<? extends Number> info){
        info.doPrint();
    }
    public static void doOther(Info<? super NullPointerException> info){
        info.doPrint();
    }
}

class Info<T>{
    private T arg01;

    public void doPrint(){
        System.out.println("arg01 = " + arg01);
    }

    public Info(T arg01) {
        this.arg01 = arg01;
    }

    public Info() {
    }

    public T getArg01() {
        return arg01;
    }

    public void setArg01(T arg01) {
        this.arg01 = arg01;
    }
}
